package com.shitou.shitouproduct.service.impl;

import com.shitou.shitoucommons.exception.RRException;
import com.shitou.shitoucommons.utils.RespBean;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shitou.shitoucommons.utils.PageUtils;
import com.shitou.shitoucommons.utils.Query;

import com.shitou.shitouproduct.dao.BrandSellProductDao;
import com.shitou.shitouproduct.entity.BrandSellProductEntity;
import com.shitou.shitouproduct.service.BrandSellProductService;


@Service("brandSellProductService")
public class BrandSellProductServiceImpl extends ServiceImpl<BrandSellProductDao, BrandSellProductEntity> implements BrandSellProductService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BrandSellProductEntity> page = this.page(
                new Query<BrandSellProductEntity>().getPage(params),
                new QueryWrapper<BrandSellProductEntity>()
        );

        return new PageUtils(page);
    }

    /**
     * 获得品牌售卖的商品
     * @param brandId
     * @return
     */
    @Override
    public RespBean getSellProductByBrandId(Long brandId, Long categoryId) {
        if ( brandId == 0 ){
            return RespBean.error("品牌出错");
        }

        List<BrandSellProductEntity> listDo = this.list(new QueryWrapper<BrandSellProductEntity>()
                .eq("brand_id", brandId).eq("category_id", categoryId)
                .eq("status", 1));
        if ( listDo.size() <= 0 ){
            return RespBean.error("该品牌暂未售卖物品,可不用选择,直接出售");
        }

        return RespBean.success().put("data", listDo);
    }

}
